/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * start.java
 *
 * Created on 10.02.2011, 21:21:35
 */
package start.gui;

//import javax.media.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import start.TestImg;
import start.pleer.MPEG_Play;
import start.pleer.MPEG_video;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import javax.imageio.ImageIO;

/**
 * @author Евгений
 */
public class pStart extends javax.swing.JPanel {

    /**
     * Creates new form start
     */
    MPEG_Play pleer;

    public pStart() {
        initComponents();
        pleer = new MPEG_Play(pVideo);
        pleer.init();
        pleer.start(getVideoStream());
        this.revalidate();
        this.repaint();
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel2 = new javax.swing.JPanel(){  public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            TestImg.getInstance().draw(this, g2);
        }} ;
        jPanel1 = new javax.swing.JPanel(){  public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            TestImg.getInstance().draw(this, g2);
        }} ;
        bNewProject = new javax.swing.JButton();
        bLoadProject = new javax.swing.JButton();
        bExit = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel(){  public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            TestImg.getInstance().draw(this, g2);
        }} ;
        pVideo = new javax.swing.JPanel();

        jPanel2.setMinimumSize(new java.awt.Dimension(200, 10));
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 20, 5));

        jPanel1.setMinimumSize(new java.awt.Dimension(200, 100));

        bNewProject.setText("Новый проект");

        bLoadProject.setText("Загрузить проект");

        bExit.setText("Выход");
        bExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bNewProject, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                    .addComponent(bLoadProject, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                    .addComponent(bExit, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bNewProject)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bLoadProject)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bExit)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel2.add(jPanel1);

        jPanel3.setLayout(new java.awt.GridBagLayout());

        pVideo.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(153, 153, 153)));
        pVideo.setMaximumSize(new java.awt.Dimension(352, 288));
        pVideo.setMinimumSize(new java.awt.Dimension(352, 288));
        pVideo.setPreferredSize(new java.awt.Dimension(352, 288));
        pVideo.setLayout(new javax.swing.BoxLayout(pVideo, javax.swing.BoxLayout.LINE_AXIS));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.weightx = 100.0;
        jPanel3.add(pVideo, gridBagConstraints);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 1154, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1154, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 443, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(376, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bExitActionPerformed
    }//GEN-LAST:event_bExitActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bExit;
    private javax.swing.JButton bLoadProject;
    private javax.swing.JButton bNewProject;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel pVideo;
    // End of variables declaration//GEN-END:variables

    public JButton getbExit() {
        return bExit;
    }

    public JButton getbLoadProject() {
        return bLoadProject;
    }

    public JButton getbNewProject() {
        return bNewProject;
    }

    public void startVideo() {
        pleer.start(getVideoStream());
        this.revalidate();
        this.repaint();
    }

    public void stopVideo() {
        pleer.stop();
    }

    public InputStream getVideoStream() {
        //String s = new File("").getAbsolutePath().replace('\\', '/') + "/video/" + "sios.mpg";
        InputStream fis = null;
        try {
            return fis = new DataInputStream(new FileInputStream(new File("res/video/sios.mpg")));

//            return fis = new DataInputStream(new FileInputStream(new File("c:\\temp\\СИОС-2.mpg")));
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return null;
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;
      TestImg.getInstance().draw(this, g2);
    }
}
